/* UTF8 Encoding */
/*-----------------------------------------------------------------------
|                            FILE DESCRIPTION                           |
-----------------------------------------------------------------------*/
/*----------------------------------------------------------------------
  - File name     : Car port
  - Author        : liuzhihua (liuzhihuawy@163.com)
  - Update date   : 2024.07.29
  - Brief         :
  - Version       : v0.1
-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
|                               UPDATE NOTE                             |
-----------------------------------------------------------------------*/
/**
  * Update note:
  * ------------   ---------------   ----------------------------------
  *     Date            Author                      Note
  * ------------   ---------------   ----------------------------------
  *  2024.07.29       liuzhihua                  Create file
***/

#ifndef CAR_PORT_H
#define CAR_PORT_H

/*-----------------------------------------------------------------------
|                               INCLUDES                                |
-----------------------------------------------------------------------*/

#ifdef  __cplusplus
    extern "C" {
#endif
#include <stdint.h>
/*-----------------------------------------------------------------------
|                                DEFINES                                |
-----------------------------------------------------------------------*/
typedef struct CarPort_typedef
{
    // id[0,1] state[0,1]
    void (*led_write)(int id, uint8_t state);
    // state[0,1]
    void (*buzzer_write)(uint8_t state);
    // [-100,100] 左轮占空比和方向
    void (*left_pwm_write)(float duty);
    // [-100,100] 右轮占空比和方向
    void (*right_pwm_write)(float duty);
    // state[0,1] 电机使能
    void (*motor_enable)(uint8_t state);
    // 返回 编码器计数值 id[0]，0：左轮，1：右轮
    int (*encoder_read)(int id);
    // 清空编码器计数值
    void (*encoder_clear)(int id);
    // 返回 电子罗盘[0,360)
    float (*angle_read)(void);
    // 返回 z轴角速度
    float (*gyroz_read)(void);
    // 循迹模块从左到右写入buf[0]为最右数据 返回写入数量
    int (*tracker_read)(uint8_t *buf, int size);
    // flash写入data 返回写入数量
    int (*flash_write)(void* data, int size);
    // flash读出到buf，返回读出数量
    int (*flash_read)(void* buf, int size);
    // 返回 电池电压
    float (*power_read)(void);
}CarPort_t;



/*-----------------------------------------------------------------------
|                                  API                                  |
-----------------------------------------------------------------------*/
// 外部调用
void CarPort_Init(void);

#ifdef __cplusplus
	}
#endif
#endif
